package 工厂模式;

/**
 * 工厂模式:
 *     通过对象工厂创建对象
 */
public class FactoryPattern {

    public interface Product {
        void execute();
    }

    public static class ProductImpl implements Product {

        @Override
        public void execute() {
            System.out.println("产品1功能实现");
        }
    }

    public static class Produc2tImpl implements Product {

        @Override
        public void execute() {
            System.out.println("产品2功能实现");
        }
    }

    /**
     * 创建对象工厂
     */
    public static class ProductFactory {

        public static Product createProduct(String productType) {
            Product product = null;
            if (productType.equals("产品1") ) {
                product = new ProductImpl();
            } else if (productType.equals("产品2")) {
                product = new Produc2tImpl();
            }
            return product;
        }
    }

    public static void main(String[] args) {
        Product product = ProductFactory.createProduct("产品1");
        product.execute();
        Product product2 = ProductFactory.createProduct("产品2");
        product2.execute();

    }
}
